/**
 * https://leetcode.cn/problems/longest-word-in-dictionary/
 */
function longestWord(words: string[]) {
  let ans = "";

  // 按照
  words.sort();

  const set = new Set<string>();

  for (let word of words) {
    if (set.has(word.substring(0, word.length - 1))) {
      ans = word.length > ans.length ? word : ans;
      set.add(word);
    }
  }

  return ans;
}
